2000W / 48V LLC Battery-Charger  V1.00
syscalls.c
Go to the documentation of this file.
1 /*********************************************************************************************************************
2  * @file syscalls.c
3  * @brief Newlib stubs
4  * @version V1.6
5  * @date 20 Apr 2017
6  *
7  * @cond
8  *********************************************************************************************************************
9  * Copyright (c) 2015-2017, Infineon Technologies AG
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
13  * following conditions are met:
14  *
15  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
16  * disclaimer.
17  *
18  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
33  * Infineon Technologies AG dave@infineon.com).
34  *********************************************************************************************************************
35  *
36  * *************************** Change history ********************************
37  * V0.1 : Initial version
38  * V0.2 : Label updates
39  * V1.0 : Made _sbrk device agnostic
40  * V1.1 : C++ support
41  * V1.2 : Restored compatibility with old project files
42  * V1.3 Jan 2014, PKB : Encapsulating everything in this file for use only with GCC
43  * V1.4 11 Dec 2015, JFT : Fix heap overflow
44  * V1.5 09 Mar 2016, JFT : Add dso_handle to support destructors call at exit
45  * V1.6 20 Apr 2017, JFT : Foward declaration of __sbrk to fix link time optimization (-flto) compilation errors
46  * @endcond
47  */
48 
49 /*
50  * This file contains stubs for standard C library functionality that must
51  * typically be provided for the underlying platform.
52  *
53  */
54 #if defined ( __GNUC__ )
55 
56 #include <stdint.h>
57 #include <errno.h>
58 #include <sys/types.h>
59 
60 /* Forward prototypes. */
61 caddr_t _sbrk(int nbytes) __attribute__((externally_visible));
62 void _init(void) __attribute__((externally_visible));
63 
64 /* c++ destructor dynamic shared object needed if -fuse-cxa-atexit is used*/
65 void *__dso_handle __attribute__ ((weak));
66 
67 // defined in linker script
68 extern caddr_t Heap_Bank1_Start;
69 extern caddr_t Heap_Bank1_End;
70 caddr_t _sbrk(int nbytes)
71 {
72  static caddr_t heap_ptr = NULL;
73  caddr_t base;
74 
75  if (heap_ptr == NULL) {
76  heap_ptr = (caddr_t)&Heap_Bank1_Start;
77  }
78 
79  base = heap_ptr;
80 
81  /* heap word alignment */
82  nbytes = (nbytes + 3) & ~0x3U;
83  if ((caddr_t)&Heap_Bank1_End > (heap_ptr + nbytes))
84  {
85  heap_ptr += nbytes;
86  return (base);
87  }
88  else
89  {
90  /* Heap overflow */
91  errno = ENOMEM;
92  return ((caddr_t)-1);
93  }
94 }
95 
96 /* Init */
97 void _init(void)
98 {}
99 
100 #endif /* __GNUC__ */
struct __attribute__((packed)) T_UINT32
Definition: cmsis_gcc.h:74